@extends('admin.main')
@section('head')
    @include('UEditor::head')
@endsection
@section('body')
    <script type="text/javascript" src="/static/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>{{isset($info['id']) ? '编辑':'新增'}}商品</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form action="" method="post" class="form-horizontal">
                <!-- 基础 -->
                <div id="tab1" class="tab-pane in tab1">
                    <div class="form-item">
                        <label class="item-label">
                            商品名称<span class="check-tips">（名称不能为空）</span>
                        </label>
                        <div class="controls">
                            <input type="text" name="goods_name" class="text input-large" placeholder="例如:娃哈哈纯净水18.9L" value="{{isset($info['goods_name']) ? $info['goods_name'] : ''}}">
                        </div>
                    </div>
                    <div class="controls">
                        <label class="item-label">商品图片</label>
                        <input type="file" id="upload_picture">
                        <input type="hidden" name="goods_img" id="goods_img" value="{{isset($info['goods_img']) ? $info['goods_img'] : ''}}"/>
                        <input type="hidden" name="img_id" id="img_id" value="{{isset($info['img_id']) ? $info['img_id'] : ''}}"/>
                        <div class="upload-img-box">
                            @if(isset($info) && $info['goods_img'])
                                <div class="upload-pre-item"><img src="/goods/imgs/{{$info['shop_id']}}/{{$info['goods_img']}}"/></div>
                            @endif
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            商品价格<span class="check-tips">（价格不能小于0）</span>
                        </label>
                        <div class="controls">
                            <input type="text" name="goods_price" class="text input-large" value="{{isset($info['goods_price']) ? $info['goods_price'] : 0}}">
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">商品分类<span class="check-tips"></span></label>
                        <div class="controls">
                            <select name="category_id">
                                @if(count($goodsCategory))
                                    @foreach($goodsCategory as $v)
                                        <option value="{{$v['id']}}"
                                                @if(isset($info['category_id']) && $info['category_id'] == $v['id']) selected @endif>{{$v['prefix']}}{{$v['title']}}</option>
                                    @endforeach
                                @endif
                            </select>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            商品库存<span class="check-tips">（价格不能小于0）</span>
                        </label>
                        <div class="controls">
                            <input type="text" name="goods_num" class="text input-large" value="{{isset($info['goods_num']) ? $info['goods_num'] : 0}}">
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">商品品牌<span class="check-tips"></span></label>
                        <div class="controls">
                            <select name="brand_id">
                                @if(count($brand))
                                    @foreach($brand as $v)
                                        <option value="{{$v['id']}}"
                                                @if(isset($info['brand_id']) && $info['brand_id'] == $v['id']) selected @endif>{{$v['title']}}</option>
                                    @endforeach
                                @endif
                            </select>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">商品详情</label>
                        <div class="controls">
                            <script id="container" name="goods_content" type="text/plain">这里写你的初始化内容</script>

                            <!-- 实例化编辑器 -->
                            <script type="text/javascript">
                                var ue = UE.getEditor('container');
                            </script>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            是否上架<span class="check-tips">（上架后才能在商城显示）</span>
                        </label>
                        <div class="controls">
                            <label class="inline radio"><input type="radio" name="check" value="0" checked>否</label>
                            <label class="inline radio"><input type="radio" name="check" value="1">是</label>
                        </div>
                    </div>
                    <script type="text/javascript">
                        //上传图片
                        /* 初始化上传插件 */
                        $("#upload_picture").uploadify({
                            "height": 30,
                            "swf": "/static/uploadify/uploadify.swf",
                            "fileObjName": "download",
                            "buttonText": "上传图片",
                            "uploader": "{{urlAdmin('file','postUploadPicture',['shop_id'=>request('shop_id')])}}",
                            "width": 120,
                            'removeTimeout': 1,
                            'fileTypeExts': '*.jpg; *.png; *.gif;',
                            "onUploadSuccess": uploadPicture,
                            'onFallback': function () {
                                alert('未检测到兼容版本的Flash.');
                            }
                        });
                        function uploadPicture(file, data) {
                            var data = $.parseJSON(data);
                            var src = '';
                            if (data.status) {
                                $("#img_id").val(data.id);
                                $("#goods_img").val(data.url);
                                src = data.url || '{{config('upload.PICTURE_UPLOAD.rootPath').request('shop_id').'/'}}' +data.savename;
                                $("#goods_img").parent().find('.upload-img-box').html(
                                        '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                                );
                            } else {
                                updateAlert(data.info);
                                setTimeout(function () {
                                    $('#top-alert').find('button').click();
                                    $(that).removeClass('disabled').prop('disabled', false);
                                }, 1500);
                            }
                        }
                    </script>
                </div>

                <!-- 高级 -->
                <div class="form-item">
                    <input type="hidden" name="id" value="{{isset($info['id']) ? $info['id'] : ''}}">
                    <button type="submit" id="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定
                    </button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                </div>
            </form>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript">
        $(function () {
            showTab();
            $("input[name=reply]").change(function () {
                var $reply = $(".form-item.reply");
                parseInt(this.value) ? $reply.show() : $reply.hide();
            }).filter(":checked").change();
        });
        //导航高亮
    </script>
@endsection
